﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
namespace NASM_Develop_IDE
{
    static class NASMBuilder
    {
        public static bool Build(string arguments,  out Process nasmP)
        {
            try
            {

                ProcessStartInfo nasm = new ProcessStartInfo("nasm", arguments);
                nasm.CreateNoWindow = true;
                nasm.RedirectStandardError = false;
                nasm.RedirectStandardInput = true;
                nasm.RedirectStandardOutput = true;
                nasm.UseShellExecute = false;                
                nasmP = new Process();
                nasmP.StartInfo = nasm;
                bool predicate = nasmP.Start();
            
                return true;
            }
            catch
            {
                nasmP = null;
                return false;
            }
        }
        public static bool Clean(string binPath)
        {
            if (binPath == null || !Directory.Exists(binPath))
            {
                throw new ArgumentException("Either path is null or it does not exist!");
            }
            else
            {
                try
                {
                    DirectoryInfo binInfo = new DirectoryInfo(binPath);
                    FileInfo[] filesInfo = binInfo.GetFiles();
                    for (int index = 0; index < filesInfo.Length; index++)
                    {
                        try
                        {
                            filesInfo[index].Delete();
                            filesInfo[index] = null;
                        }
                        catch
                        {
                            break;
                        }
                    }
                    GC.Collect();
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
    }
}
